<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是STM32开发——IAP编程实现的一些相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV16-27-内部Flash-04-IAP编程实现">
<meta property="og:url" content="https://sumumm.github.io/post/42407839.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是STM32开发——IAP编程实现的一些相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925122206196.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925122830611.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925145628360.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925124632044.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925125440893.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925125638731.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925125826599.png">
<meta property="article:published_time" content="2023-06-04T14:07:50.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.015Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV16-STM32开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925122206196.png">


<link rel="canonical" href="https://sumumm.github.io/post/42407839.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/42407839.html","path":"post/42407839.html","title":"LV16-27-内部Flash-04-IAP编程实现"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV16-27-内部Flash-04-IAP编程实现 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81APP%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E5%88%B6%E4%BD%9C"><span class="nav-text">一、APP应用程序制作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-APP%E8%B5%B7%E5%A7%8B%E5%9C%B0%E5%9D%80%E8%AE%BE%E7%BD%AE"><span class="nav-text">1.APP起始地址设置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-FLASH%E4%B8%AD%E8%BF%90%E8%A1%8C"><span class="nav-text">1.1 FLASH中运行</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-SRAM%E4%B8%AD%E8%BF%90%E8%A1%8C"><span class="nav-text">1.2 SRAM中运行</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-%E8%AE%BE%E7%BD%AE%E6%88%90%E5%8A%9F%E5%88%A4%E5%AE%9A"><span class="nav-text">1.3 设置成功判定</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E4%B8%AD%E6%96%AD%E5%90%91%E9%87%8F%E8%A1%A8%E5%81%8F%E7%A7%BB"><span class="nav-text">2. 中断向量表偏移</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-FLASH-%E4%B8%AD%E8%BF%90%E8%A1%8C"><span class="nav-text">2.1 FLASH 中运行</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-SRAM%E4%B8%AD%E8%BF%90%E8%A1%8C"><span class="nav-text">2.2 SRAM中运行</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-bin%E6%96%87%E4%BB%B6%E7%9A%84%E7%94%9F%E6%88%90"><span class="nav-text">3. bin文件的生成</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E7%94%9F%E6%88%90%E5%B7%A5%E5%85%B7"><span class="nav-text">3.1 生成工具</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-MDK%E9%85%8D%E7%BD%AE"><span class="nav-text">3.2 MDK配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-APP%E7%94%9F%E6%88%90%E6%80%BB%E7%BB%93"><span class="nav-text">4. APP生成总结</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81Bootloader%E7%BC%96%E5%86%99"><span class="nav-text">二、Bootloader编写</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-APP%E7%A8%8B%E5%BA%8F%E8%B7%B3%E8%BD%AC"><span class="nav-text">1. APP程序跳转</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88"><span class="nav-text">1.1 函数指针</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E9%87%8D%E8%AE%BE%E6%A0%88%E9%A1%B6%E6%8C%87%E9%92%88"><span class="nav-text">1.2 重设栈顶指针</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-%E8%B7%B3%E8%BD%AC%E5%AE%9E%E7%8E%B0"><span class="nav-text">1.3 跳转实现</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-APP%E7%A8%8B%E5%BA%8F%E6%8E%A5%E6%94%B6"><span class="nav-text">2. APP程序接收</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-APP%E7%A8%8B%E5%BA%8F%E5%86%99%E5%85%A5"><span class="nav-text">3. APP程序写入</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-APP%E5%86%99%E5%85%A5%E5%86%85%E9%83%A8FLASH"><span class="nav-text">3.1 APP写入内部FLASH</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-APP%E5%86%99%E5%85%A5%E5%86%85%E9%83%A8SRAM"><span class="nav-text">3.2 APP写入内部SRAM</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-APP%E6%89%A7%E8%A1%8C%E5%AE%9E%E4%BE%8B"><span class="nav-text">4. APP执行实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E6%89%A7%E8%A1%8CFLASH%E4%B8%AD%E7%9A%84APP"><span class="nav-text">4.1 执行FLASH中的APP</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E6%89%A7%E8%A1%8CSRAM%E4%B8%AD%E7%9A%84APP"><span class="nav-text">4.2 执行SRAM中的APP</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/42407839.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV16-27-内部Flash-04-IAP编程实现 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV16-27-内部Flash-04-IAP编程实现
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-06-04 22:07:50" itemprop="dateCreated datePublished" datetime="2023-06-04T22:07:50+08:00">2023-06-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV16-STM32开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>5.2k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>19 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是STM32开发——IAP编程实现的一些相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center">开发板</td>        <td align="left">正点原子 i.MX6ULL Linux阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">STM32开发板</td>        <td align="left">正点原子战舰V3(STM32F103ZET6)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <ul><li>通用</li></ul><table><tr><td align="center">分类  </td><td align="center">网址</td><td align="center">说明</td></tr><tr><td align="center" rowspan="4">官方网站</td><td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td><td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td></tr><tr>                                            <td align="left"><a href="https://www.st.com/content/st_com/zh.html" target="_blank">https://www.st.com/content/st_com/zh.html</a></td><td align="left">ST官方网站，在这里我们可以找到STM32的相关文档</td></tr><tr>                                            <td align="left"><a href="https://www.stmcu.com.cn/" target="_blank">https://www.stmcu.com.cn/</a></td><td align="left">意法半导体ST中文官方网站，在这里我们可以找到STM32的相关中文参考文档</td></tr><tr>                                            <td align="left"><a href="http://elm-chan.org/fsw/ff/00index_e.html" target="_blank">http://elm-chan.org/fsw/ff/00index_e.html</a></td><td align="left">FatFs文件系统官网</td></tr><tr><td align="center" rowspan="3">教程书籍</td><td align="left"><a href="STM32开发相关资料/01ARM参考资料/ARM Cortex-M3权威指南(中文).pdf" target="_blank">《ARM Cortex-M3权威指南》</a></td><td alirn="left" rowspan="3">ARM公司专家Joseph Yiu（姚文祥）的力作，中文翻译是NXP的宋岩</td></tr><tr>                                            <td align="left"><a href="STM32开发相关资料/01ARM参考资料/ARM Cortex-M0权威指南(中文).pdf" target="_blank">《ARM Cortex-M0权威指南》</a></td></tr><tr>                                            <td align="left"><a href="" target="_blank">《ARM Cortex-M3与Cortex-M4权威指南》</a></td></tr><tr><td align="center" rowspan="4">开发论坛</td><td align="left"><a href="http://47.111.11.73/forum.php" target="_blank">http://47.111.11.73/forum.php</a></td><td align="left">开源电子网，正点原子的资料下载及问题讨论论坛</td></tr><tr>                                            <td align="left"><a href="https://www.firebbs.cn/forum.php" target="_blank">https://www.firebbs.cn/forum.php</a></td><td align="left">国内Kinetis开发板-野火/秉火（刘火良）主持的论坛，现也做STM32和i.MX RT</td></tr><tr>                                            <td align="left"><a href="https://www.amobbs.com/index.php" target="_blank">https://www.amobbs.com/index.php</a></td><td align="left">阿莫（莫进明）主持的论坛，号称国内最早最火的电子论坛，以交流Atmel AVR系列单片机起家，现已拓展到嵌入式全平台，其STM32系列帖子有70W+。</td></tr><tr>                                            <td align="left"><a href="http://download.100ask.net/index.html" target="_blank">http://download.100ask.net/index.html</a></td><td align="left">韦东山嵌入式资料中心，有些STM32和linux的相关资料也可以来这里找。</td></tr><tr><td align="center" rowspan="3">博客参考</td><td align="left"><a href="http://www.openedv.com/" target="_blank">http://www.openedv.com/</a></td><td align="left">开源网-原子哥个人博客</td></tr><tr>                                            <td align="left"><a href="http://blog.chinaaet.com/jihceng0622" target="_blank">http://blog.chinaaet.com/jihceng0622</a></td><td align="left">博主是原Freescale现NXP的现场应用工程师</td></tr><tr>                                            <td align="left"><a href="https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/cortex-m-resources" target="_blank">cortex-m-resources</a></td><td align="left">这其实并不算是一个博客，这是ARM公司专家Joseph Yiu收集整理的所有对开发者有用的官方Cortex-M资料链接（也包含极少数外部资源链接）</td></tr></table><ul><li>STM32</li></ul><table>    <tr><td align="center" rowspan="2">STM32</td><td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103/hal_general/zh/latest/index.html" target="_blank">STM32 HAL库开发实战指南——基于F103系列开发板</a></td><td align="left">野火STM32开发教程在线文档</td></tr><tr>                                            <td align="left"><a href="https://doc.embedfire.com/mcu/stm32/f103badao/std/zh/latest/index.html" target="_blank">STM32库开发实战指南——基于野火霸道开发板</a></td><td align="left">野火STM32开发教程在线文档</td></tr></table><ul><li>SD卡</li></ul><table>    <tr><td align="left"><a href="https://www.sdcard.org/" target="_blank">SD Association</a></td><td align="left">提供了SD存储卡和SDIO卡系统规范</td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr><td align="left"><a href="https://www.st.com/resource/en/datasheet/stm32f103ze.pdf" target="_blank">STM32F103xx英文数据手册</a></td><td align="left">STM32F103xC/D/E系列的英文数据手册</td></tr>    <tr><td align="left"><a href="https://www.stmcu.com.cn/Designresource/detail/localization_document%20/709978" target="_blank">STM32F103xx中文数据手册</a></td><td align="left">STM32F103xC/D/E系列的中文数据手册</td></tr>    <tr><td align="left"><a href="https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf" target="_blank">STM32F10xxx英文参考手册（RM0008）</a></td><td align="left">STM32F10xxx系列的英文参考手册</td></tr>    <tr><td align="left"><a href="https://www.stmcu.com.cn/Designresource/detail/localization_document%20/710001" target="_blank">STM32F10xxx中文参考手册（RM0008）</a></td><td align="left">STM32F10xxx系列的中文参考手册</td></tr>    <tr><td align="left"><a href="https://developer.arm.com/documentation/100165/0201/?lang=en" target="_blank">Arm Cortex-M3 处理器技术参考手册-英文版</a></td><td align="left">Cortex-M3技术参考手册-英文版</td></tr>    <tr><td align="left"><a href="https://www.st.com/resource/en/programming_manual/pm0056-stm32f10xxx20xxx21xxxl1xxxx-cortexm3-programming-manual-stmicroelectronics.pdf" target="_blank">STM32F10xxx Cortex-M3编程手册-英文版(PM0056)</a></td><td align="left">STM32F10xxx/20xxx/21xxx/L1xxxx系列Cortex-M3编程手册-英文版</td></tr>    <tr><td align="left"><a href="https://www.sdcard.org/downloads/pls/" target="_blank">SD卡相关资料——最新版本</a></td><td align="left">有关SD卡的一些资料可以从这里下载</td></tr>    <tr><td align="left"><a href="https://www.sdcard.org/downloads/pls/archives/" target="_blank">SD卡相关资料——历史版本</a></td><td align="left">有关SD卡的一些历史版本资料可以从这里下载，比如后边看的SD卡2.0协议</td></tr>    <tr><td align="left"><a href="./" target="_blank">SD 2.0 协议标准完整版</a></td><td align="left">这是一篇关于SD卡2.0协议的中文文档，还是比较有参考价值的，可以一看</td></tr></table>
              </div>
            </details> 

<h1 id="一、APP应用程序制作"><a href="#一、APP应用程序制作" class="headerlink" title="一、APP应用程序制作"></a><font size=3>一、APP应用程序制作</font></h1><p>STM32 的 APP 程序不仅可以放到 FLASH 里面运行，也可以放到 SRAM 里面运行，  我们使用的STM32F103ZET6有512KB的FLASH和64KB的SRAM，FLASH的地址为 0x0800 0000 ~ 0x0807 FFFF，内部SRAM的地址为 0x2000 0000 ~ 0x2000 FFFF。</p>
<h2 id="1-APP起始地址设置"><a href="#1-APP起始地址设置" class="headerlink" title="1.APP起始地址设置"></a><font size=3>1.APP起始地址设置</font></h2><h3 id="1-1-FLASH中运行"><a href="#1-1-FLASH中运行" class="headerlink" title="1.1 FLASH中运行"></a><font size=3>1.1 FLASH中运行</font></h3><ul>
<li>【Options for Target】&rarr;【Target】</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925122206196.png" alt="image-20220925122206196" style="zoom:50%;" />

<p>默认的条件下，图中 IROM1 的起始地址（Start）一般为 0x0800 0000，大小（Size）为 0x80000，即从 0x08000000 开始的 512K 空间为我们的程序存储（因为我们的 STM32F103ZET6 的 FLASH大小是 512K）。</p>
<p>而当前图中，我们设置IROM1的起始地址（Start）为 0X0801 0000，即偏移量为 0X10000（64K 字节）。因而，留给 APP用的 FLASH 空间（Size）为0x80000 - 0x10000&#x3D; 0x70000（448K字节）。</p>
<p>设置好 Start 和 Szie，就完成 APP 程序的起始地址设置。这里的 64K 字节，需要我们根据 Bootloader 程序大小进行选择，理论上我们只需要确保 APP 起始地址在 Bootloader 程序之后，并且偏移量为 0x200 的倍数即可（为什么是0x200的倍数？<a target="_blank" rel="noopener" href="http://www.openedv.com/posts/list/392.htm">NVIC的向量表偏移寄存器设置问题(已解决)-OpenEdv-开源电子网</a>）。这里我们选择 64K（0x10000）字节，留了一些余量，可以方便 Bootloader 以后的升级修改。 我们编译完成后，可以看一下它的sct文件：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">; *************************************************************</span><br><span class="line">; *** Scatter-Loading Description File generated by uVision ***</span><br><span class="line">; *************************************************************</span><br><span class="line"></span><br><span class="line">LR_IROM1 <span class="number">0x08010000</span> <span class="number">0x00070000</span>  &#123;    ; load region size_region</span><br><span class="line">  ER_IROM1 <span class="number">0x08010000</span> <span class="number">0x00070000</span>  &#123;  ; load address = execution address</span><br><span class="line">   *.o (RESET, +First)</span><br><span class="line">   *(InRoot$$Sections)</span><br><span class="line">   .ANY (+RO)</span><br><span class="line">   .ANY (+XO)</span><br><span class="line">  &#125;</span><br><span class="line">  RW_IRAM1 <span class="number">0x20000000</span> <span class="number">0x00010000</span>  &#123;  ; RW data</span><br><span class="line">   .ANY (+RW +ZI)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="1-2-SRAM中运行"><a href="#1-2-SRAM中运行" class="headerlink" title="1.2 SRAM中运行"></a><font size=3>1.2 SRAM中运行</font></h3><p>若APP在SRAM中运行的话，我们设置的方式也类似：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925122830611.png" alt="image-20220925122830611" style="zoom:50%;" />

<p>这里我们将 IROM1 的起始地址（Start）定义为： 0x20001000，大小为 0xC000（48K 字节），即从地址 0x20000000 偏移 0x1000 开始，存放 APP 代码。因为整个 STM32F103ZET6 的 SRAM大小为64K字节，所以 IRAM1（ SRAM ）的起始地址变为 0x2000D000（ 0x20001000 + 0xC000&#x3D;0x2000D000 ），大小只有 0x3000 （ 12K字节 ）。 </p>
<p>这样，整个STM32F103ZET6 的 SRAM 分配情况为：最开始的 4K 给 Bootloader 程序使用，随后的 48K 存放 APP 程序，最后12K，用作 APP 程序的内存。这个分配关系我们可以根据自己的实际情况修改，不一定和这里的设置一模一样，不过也需要注意，保证偏移量为 0X200 的倍数（我们这里为 0X1000）。我们看一下它的sct文件：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">; *************************************************************</span><br><span class="line">; *** Scatter-Loading Description File generated by uVision ***</span><br><span class="line">; *************************************************************</span><br><span class="line"></span><br><span class="line">LR_IROM1 <span class="number">0x20001000</span> <span class="number">0x0000C000</span>  &#123;    ; load region size_region</span><br><span class="line">  ER_IROM1 <span class="number">0x20001000</span> <span class="number">0x0000C000</span>  &#123;  ; load address = execution address</span><br><span class="line">   *.o (RESET, +First)</span><br><span class="line">   *(InRoot$$Sections)</span><br><span class="line">   .ANY (+RO)</span><br><span class="line">   .ANY (+XO)</span><br><span class="line">  &#125;</span><br><span class="line">  RW_IRAM1 <span class="number">0x2000D000</span> <span class="number">0x00003000</span>  &#123;  ; RW data</span><br><span class="line">   .ANY (+RW +ZI)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="1-3-设置成功判定"><a href="#1-3-设置成功判定" class="headerlink" title="1.3 设置成功判定"></a><font size=3>1.3 设置成功判定</font></h3><p>那怎么知道设置后是否成功呢？我们可以看存储器映像中的信息，就是前边学习FLASH时说过的 .map 文件中的 Memory Map of the image 部分：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Image Entry point : 0x08000131</span><br><span class="line"></span><br><span class="line">Load Region LR_IROM1 (Base: 0x08000000, Size: 0x00007770, Max: 0x00080000, ABSOLUTE)</span><br><span class="line"></span><br><span class="line">Execution Region ER_IROM1 (Exec base: 0x08000000, Load base: 0x08000000, Size: 0x00007730, Max: 0x00080000, ABSOLUTE)</span><br></pre></td></tr></table></figure>

<p>需要注意的是，有时候我们更改了 IROM1 后，这里并没有任何变化，此时我们需要修改这里：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925145628360.png" alt="image-20220925145628360" style="zoom: 33%;" />

<p>重新设定之后，重新编译查看即可。</p>
<h2 id="2-中断向量表偏移"><a href="#2-中断向量表偏移" class="headerlink" title="2. 中断向量表偏移"></a><font size=3>2. 中断向量表偏移</font></h2><p>在系统启动的时候，会首先调用 SystemInit() 函数初始化时钟系统，同时SystemInit() 还完成了中断向量表的设置，我们可以打开 SystemInit() 函数，看看函数体的结尾处有这样几行代码 </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  Setup the microcontroller system</span></span><br><span class="line"><span class="comment">  *         Initialize the Embedded Flash Interface, the PLL and update the </span></span><br><span class="line"><span class="comment">  *         SystemCoreClock variable.</span></span><br><span class="line"><span class="comment">  * @note   This function should be used only after reset.</span></span><br><span class="line"><span class="comment">  * @param  None</span></span><br><span class="line"><span class="comment">  * @retval None</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">SystemInit</span> <span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="comment">// ... ...</span></span><br><span class="line"><span class="meta">#<span class="keyword">ifdef</span> VECT_TAB_SRAM</span></span><br><span class="line">  SCB-&gt;VTOR = SRAM_BASE | VECT_TAB_OFFSET; <span class="comment">/* Vector Table Relocation in Internal SRAM. */</span></span><br><span class="line"><span class="meta">#<span class="keyword">else</span></span></span><br><span class="line">  SCB-&gt;VTOR = FLASH_BASE | VECT_TAB_OFFSET; <span class="comment">/* Vector Table Relocation in Internal FLASH. */</span></span><br><span class="line"><span class="meta">#<span class="keyword">endif</span> </span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>从这里可以看出VTOR寄存器存放的是中断向量表的起始地址。默认的情况 VECT_TAB_SRAM 是没有定义，所以执行:</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SCB-&gt;VTOR = FLASH_BASE | VECT_TAB_OFFSET;</span><br></pre></td></tr></table></figure>

<p>另外，SystemInit()函数的执行是在启动文件的复位中断中：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">; Reset handler</span><br><span class="line">Reset_Handler   PROC</span><br><span class="line">                EXPORT  Reset_Handler             [WEAK]</span><br><span class="line">                IMPORT  __main</span><br><span class="line">                IMPORT  SystemInit</span><br><span class="line">                LDR     R0, =SystemInit</span><br><span class="line">                BLX     R0               </span><br><span class="line">                LDR     R0, =__main</span><br><span class="line">                BX      R0</span><br><span class="line">                ENDP</span><br></pre></td></tr></table></figure>

<p>【注意】</p>
<p>（1）这里只是举一个例子，看一下中断向量表怎么设置，后边直接设置这个 SCB-&gt;VTOR 即可。</p>
<p>（2）FLASH中APP和SRAM中APP的中断向量表地址设置与前边APP偏移地址相关联，注意要跟前边对应。</p>
<h3 id="2-1-FLASH-中运行"><a href="#2-1-FLASH-中运行" class="headerlink" title="2.1 FLASH 中运行"></a><font size=3>2.1 FLASH 中运行</font></h3><p>对于 FLASH中的APP，我们设置为 FLASH_BASE+偏移量 0x10000，所以我们可以在 FLASH中APP 的 main 函数最开头处添加如下代码实现中断向量表的起始地址的重设：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SCB-&gt;VTOR = FLASH_BASE | <span class="number">0x10000</span>;</span><br></pre></td></tr></table></figure>

<h3 id="2-2-SRAM中运行"><a href="#2-2-SRAM中运行" class="headerlink" title="2.2 SRAM中运行"></a><font size=3>2.2 SRAM中运行</font></h3><p>当使用 SRAM APP 的时候， 我们设置起始地址为：SRAM_BASE + 0x1000,同样的方法，我们在 SRAM APP 的 main 函数最开始处，添加下面代码：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">SCB-&gt;VTOR = SRAM_BASE | <span class="number">0x1000</span>;</span><br></pre></td></tr></table></figure>

<p>这样，我们就完成了中断向量表偏移量的设置。  </p>
<h2 id="3-bin文件的生成"><a href="#3-bin文件的生成" class="headerlink" title="3. bin文件的生成"></a><font size=3>3. bin文件的生成</font></h2><h3 id="3-1-生成工具"><a href="#3-1-生成工具" class="headerlink" title="3.1 生成工具"></a><font size=3>3.1 生成工具</font></h3><p>我们使用的 MDK 默认生成的文件是 .hex 文件，并不方便我们用作 IAP更新，我们希望生成的文件是 .bin 文件，这样可以方便进行 IAP 升级。MDK 自带的格式转换工具 fromelf.exe，可以实现 .axf 文件到 .bin 文件的转换。该工具在 MDK 的安装目录的这个文件夹下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">windows 下的路径格式</span></span><br><span class="line">\ARM\ARMCC\bin</span><br></pre></td></tr></table></figure>



<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925124632044.png" alt="image-20220925124632044" style="zoom:50%;" />



<p>fromelf.exe 转换工具的语法格式为： </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fromelf [options] input_file</span><br></pre></td></tr></table></figure>

<p>其中 options 有很多选项可以设置 ，其他的没有研究过，这里就直接用下边的命令格式即可（这是我当时安装MDK的路径）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">C:\LenovoSoft\Keil_v5\ARM\ARMCC\bin\fromelf.exe --bin -o ..\OBJ_dir\xxx.bin ..\OBJ_dir\xxx.axf</span><br></pre></td></tr></table></figure>

<h3 id="3-2-MDK配置"><a href="#3-2-MDK配置" class="headerlink" title="3.2 MDK配置"></a><font size=3>3.2 MDK配置</font></h3><ul>
<li>（1）确认生成的可执行文件名和输出文件的文件夹路径</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925125440893.png" alt="image-20220925125440893" style="zoom:50%;" />

<ul>
<li>（2）添加命令</li>
</ul>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925125638731.png" alt="image-20220925125638731" style="zoom:50%;" />

<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">C:\LenovoSoft\Keil_v5\ARM\ARMCC\bin\fromelf.exe --bin -o  ..\OBJ\TOUCH.bin ..\OBJ\TOUCH.axf</span><br></pre></td></tr></table></figure>

<ul>
<li>（3）编译工程</li>
</ul>
<p>编译整个工程，编译结束后，我们会看到如下提示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV16-STM32%E5%BC%80%E5%8F%91/LV16-27-%E5%86%85%E9%83%A8Flash-04-IAP%E7%BC%96%E7%A8%8B%E5%AE%9E%E7%8E%B0/img/image-20220925125826599.png" alt="image-20220925125826599" style="zoom:50%;" />

<p>然后我们就可以看到生成的 .bin 文件啦。</p>
<h2 id="4-APP生成总结"><a href="#4-APP生成总结" class="headerlink" title="4. APP生成总结"></a><font size=3>4. APP生成总结</font></h2><ul>
<li><p>（1）设置 APP 程序的起始地址和存储空间大小。对于在 FLASH 里面运行的 APP 程序和 SRAM 里面运行的 APP 程序，他们的设置类似，但是要注意各个地址。</p>
</li>
<li><p>（2）设置中断向量表偏移量。主要就是APP的main函数中设置 SCB-&gt;VTOR 的值 。</p>
</li>
<li><p>（3）设置编译后运行 fromelf.exe，生成 .bin 文件。通过在 User 选项卡，设置编译后调用 fromelf.exe，根据.axf 文件生成.bin 文件，用于IAP 更新。</p>
</li>
</ul>
<h1 id="二、Bootloader编写"><a href="#二、Bootloader编写" class="headerlink" title="二、Bootloader编写"></a><font size=3>二、Bootloader编写</font></h1><p>前边我们已经完成了APP的制作，那么现在要做的就是通过Bootloader程序将APP程序写入到相应的地址，并跳转执行。</p>
<h2 id="1-APP程序跳转"><a href="#1-APP程序跳转" class="headerlink" title="1. APP程序跳转"></a><font size=3>1. APP程序跳转</font></h2><h3 id="1-1-函数指针"><a href="#1-1-函数指针" class="headerlink" title="1.1 函数指针"></a><font size=3>1.1 函数指针</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span>  <span class="title function_">void</span> <span class="params">(*pIAPFunc)</span><span class="params">(<span class="type">void</span>)</span>;				<span class="comment">//定义一个函数类型的参数.</span></span><br><span class="line">pIAPFunc jump2app;  <span class="comment">// 定义一个函数指针变量</span></span><br></pre></td></tr></table></figure>

<p>jump2app是一个函数指针变量，可以指向一个不含参数，且无返回值的函数。</p>
<h3 id="1-2-重设栈顶指针"><a href="#1-2-重设栈顶指针" class="headerlink" title="1.2 重设栈顶指针"></a><font size=3>1.2 重设栈顶指针</font></h3><p>重新设置栈顶指针，因为STM32启动的时候就需要获取栈顶指针，防止堆栈溢出，设置栈顶指针的话需要使用汇编，我们可以自己实现：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  设置栈顶指针的地址</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  addr 栈顶指针的地址</span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line">__asm <span class="type">void</span> <span class="title function_">MSR_MSP</span><span class="params">(u32 addr)</span></span><br><span class="line">&#123;</span><br><span class="line">    MSR MSP, r0 <span class="comment">// set Main Stack value</span></span><br><span class="line">    BX r14</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>后来发现，其实STM32的核心标准文件中已经为我们实现了相关的设置栈顶指针的函数，它在 cmsis_armcc.h 文件中，函数实现如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  \brief   Set Main Stack Pointer</span></span><br><span class="line"><span class="comment">  \details Assigns the given value to the Main Stack Pointer (MSP).</span></span><br><span class="line"><span class="comment">  \param [in]    topOfMainStack  Main Stack Pointer value to set</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">__STATIC_INLINE <span class="type">void</span> __set_MSP(<span class="type">uint32_t</span> topOfMainStack)</span><br><span class="line">&#123;</span><br><span class="line">  <span class="keyword">register</span> <span class="type">uint32_t</span> __regMainStackPointer     __ASM(<span class="string">&quot;msp&quot;</span>);</span><br><span class="line">  __regMainStackPointer = topOfMainStack;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>注意，这个函数在 cmsis_gcc.h 文件中也有一个，注意不要包含错头文件了。</p>
<h3 id="1-3-跳转实现"><a href="#1-3-跳转实现" class="headerlink" title="1.3 跳转实现"></a><font size=3>1.3 跳转实现</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  跳转到应用程序段</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  appxaddr 用户代码起始地址</span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">iap_load_app</span><span class="params">(<span class="type">uint32_t</span> appxaddr)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">if</span> (((*(__IO <span class="type">uint32_t</span> *)appxaddr) &amp; <span class="number">0x2FFE0000</span>) == <span class="number">0x20000000</span>) <span class="comment">// 检查栈顶地址是否合法.</span></span><br><span class="line">    &#123;</span><br><span class="line">        jump2app = (pIAPFunc) * (__IO <span class="type">uint32_t</span> *)(appxaddr + <span class="number">4</span>);   <span class="comment">// 用户代码区第二个字为程序开始地址(复位地址)</span></span><br><span class="line">        __set_MSP(*(__IO <span class="type">uint32_t</span> *)appxaddr);                     <span class="comment">// 初始化APP堆栈指针(用户代码区的第一个字用于存放栈顶地址)</span></span><br><span class="line">        jump2app();                                                <span class="comment">// 跳转到APP.</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>第9行：校验一下即将运行的APP的栈顶指针是否位于内部SRAM区域。</p>
<p>第11行：将函数指针指向应用程序的起始起始地址，这里的起始地址应该是app应用程序的基地址再加4个字节，加上四个字节后，这个函数指针就指向了app应用程序的复位中断向量子程序。</p>
<p>第12行：设置栈顶的地址，为C语言运行提供环境，app的基地址存储的就是栈顶地址。</p>
<p>第13行：就相当于执行函数，执行了复位中断子程序，之后便会进入应用app的main死循环中。</p>
<h2 id="2-APP程序接收"><a href="#2-APP程序接收" class="headerlink" title="2. APP程序接收"></a><font size=3>2. APP程序接收</font></h2><p>我们这里通过串口来接收APP应用程序（.bin）文件。这里只列出部分关键代码。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//注意,读取USARTx-&gt;SR能避免莫名其妙的错误</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> USART_REC_LEN 55*1024 <span class="comment">//定义最大接收字节数 55K</span></span></span><br><span class="line"><span class="type">uint8_t</span> USART_RX_BUF[USART_REC_LEN] __attribute__ ((at(<span class="number">0X20001000</span>))); <span class="comment">//接收缓冲,最大USART_REC_LEN个字节,起始地址为0X20001000.</span></span><br><span class="line"></span><br><span class="line"><span class="type">uint16_t</span> USART_RX_CNT=<span class="number">0</span>; <span class="comment">// 接收的字节数</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 串口1中断服务程序</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">USART1_IRQHandler</span><span class="params">(<span class="type">void</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">	<span class="type">uint8_t</span> res;	</span><br><span class="line">	<span class="keyword">if</span>(USART1-&gt;SR &amp; (<span class="number">1</span>&lt;&lt;<span class="number">5</span>))<span class="comment">//接收到数据</span></span><br><span class="line">	&#123;	 </span><br><span class="line">		res = USART1-&gt;DR; </span><br><span class="line">		<span class="keyword">if</span>(USART_RX_CNT &lt; USART_REC_LEN)</span><br><span class="line">		&#123;</span><br><span class="line">			USART_RX_BUF[USART_RX_CNT] = res;</span><br><span class="line">			USART_RX_CNT++;			 									     </span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>我们指定 USART_RX_BUF 的地址是从 0X20001000 开始，该地址也就是 SRAM中APP程序的起始地址。 然后串口1的中断服务程序（USART1_IRQHandler() 函数）里面，将串口发送过来的数据，全部接收到 USART_RX_BUF，并通过 USART_RX_CNT 计数，这样接收数据的同时，还可以获取整个文件的大小。不过这里这个55KB太大了，很有可能造成我们的代码内存不够用，编译都通不过，所以Bootloader的代码也不能做太多的功能，只要能完成基本的程序的接收和写入还有跳转就可以了。  </p>
<h2 id="3-APP程序写入"><a href="#3-APP程序写入" class="headerlink" title="3. APP程序写入"></a><font size=3>3. APP程序写入</font></h2><h3 id="3-1-APP写入内部FLASH"><a href="#3-1-APP写入内部FLASH" class="headerlink" title="3.1 APP写入内部FLASH"></a><font size=3>3.1 APP写入内部FLASH</font></h3><p>若是这是一个FALSH中的APP，我们就还需要将该 .bin 文件写入到FLASH相应的地址中去。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">uint16_t</span> iapbuf[<span class="number">1024</span>];</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">  * @brief  将接收的bin文件写入指定的地址</span></span><br><span class="line"><span class="comment">  * @note   </span></span><br><span class="line"><span class="comment">  * @param  appxaddr 应用程序的起始地址</span></span><br><span class="line"><span class="comment">  * @param  appbuf 应用程序CODE.</span></span><br><span class="line"><span class="comment">  * @param  appsize 应用程序大小(字节).</span></span><br><span class="line"><span class="comment">  * @retval </span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line"><span class="type">void</span> <span class="title function_">iap_write_appbin</span><span class="params">(<span class="type">uint32_t</span> appxaddr, <span class="type">uint8_t</span> *appbuf, <span class="type">uint32_t</span> appsize)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">uint16_t</span> t;</span><br><span class="line">    <span class="type">uint16_t</span> i = <span class="number">0</span>;</span><br><span class="line">    <span class="type">uint16_t</span> temp;</span><br><span class="line">    <span class="type">uint32_t</span> fwaddr = appxaddr; <span class="comment">// 当前写入的地址</span></span><br><span class="line">    <span class="type">uint8_t</span> *dfu = appbuf;</span><br><span class="line">    <span class="keyword">for</span> (t = <span class="number">0</span>; t &lt; appsize; t += <span class="number">2</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        temp = (<span class="type">uint16_t</span>)dfu[<span class="number">1</span>] &lt;&lt; <span class="number">8</span>;</span><br><span class="line">        temp += (<span class="type">uint16_t</span>)dfu[<span class="number">0</span>];</span><br><span class="line">        dfu += <span class="number">2</span>; <span class="comment">// 偏移2个字节</span></span><br><span class="line">        iapbuf[i++] = temp;</span><br><span class="line">        <span class="keyword">if</span> (i == <span class="number">1024</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            i = <span class="number">0</span>;</span><br><span class="line">            internalFLASH_Write(fwaddr, iapbuf, <span class="number">1024</span>); </span><br><span class="line">            fwaddr += <span class="number">2048</span>; <span class="comment">// 偏移2048  16=2*8.所以要乘以2.</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (i)</span><br><span class="line">    &#123;</span><br><span class="line">        internalFLASH_Write(fwaddr, iapbuf, i); <span class="comment">// 将最后的一些内容字节写进去.</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>该函数用于将FLASH APP写入到FLASH中指定的区域中。internalFLASH_Write()函数需要自己实现，具体可以看<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/stm32f103-prj/blob/master/Hardware/internalFlash.c">Hardware&#x2F;internalFlash.c · sumumm&#x2F;STM32F103-Prj - 码云 - 开源中国 (gitee.com)</a></p>
<h3 id="3-2-APP写入内部SRAM"><a href="#3-2-APP写入内部SRAM" class="headerlink" title="3.2 APP写入内部SRAM"></a><font size=3>3.2 APP写入内部SRAM</font></h3><p>由于我们通过串口直接将接收到的数据写入了内部SRAM中，且SRAM中运行的APP我们在设置地址的时候，跟串口接收写入的地址是一致的，所以这里并不需要将 .bin 文件再写入到SRAM，我们可以直接跳转运行。</p>
<h2 id="4-APP执行实例"><a href="#4-APP执行实例" class="headerlink" title="4. APP执行实例"></a><font size=3>4. APP执行实例</font></h2><h3 id="4-1-执行FLASH中的APP"><a href="#4-1-执行FLASH中的APP" class="headerlink" title="4.1 执行FLASH中的APP"></a><font size=3>4.1 执行FLASH中的APP</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//执行FLASH APP</span></span><br><span class="line"><span class="keyword">if</span>(((*(__IO <span class="type">uint32_t</span> *)(<span class="number">0x08010000</span> + <span class="number">4</span>)) &amp; <span class="number">0xFF000000</span>)==<span class="number">0x08000000</span>)<span class="comment">//判断是否为0X08XXXXXX.</span></span><br><span class="line">&#123;	 </span><br><span class="line">    iap_load_app(<span class="number">0x08010000</span>);<span class="comment">// 执行FLASH APP代码</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="4-2-执行SRAM中的APP"><a href="#4-2-执行SRAM中的APP" class="headerlink" title="4.2 执行SRAM中的APP"></a><font size=3>4.2 执行SRAM中的APP</font></h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 执行SRAM APP</span></span><br><span class="line"><span class="keyword">if</span>(((*(__IO uint32 *)(<span class="number">0X20001000</span> + <span class="number">4</span>)) &amp; <span class="number">0xFF000000</span>)==<span class="number">0x20000000</span>)<span class="comment">//判断是否为0X20XXXXXX.</span></span><br><span class="line">&#123;	 </span><br><span class="line">    iap_load_app(<span class="number">0X20001000</span>);<span class="comment">// SRAM地址</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/42407839.html">LV16-27-内部Flash-04-IAP编程实现</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年06月04日 - 22:07</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/42407839.html" title="LV16-27-内部Flash-04-IAP编程实现">https://sumumm.github.io/post/42407839.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV16-STM32%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> LV16-STM32开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/3878988b.html" rel="prev" title="LV16-28-Memory-01-内存管理基础">
                  <i class="fa fa-angle-left"></i> LV16-28-Memory-01-内存管理基础
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/e506a5ec.html" rel="next" title="LV16-27-内部Flash-03-IAP编程基础">
                  LV16-27-内部Flash-03-IAP编程基础 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
